package com.atguigu.gmall.task.config;

import com.atguigu.gmall.common.constant.MqConst;
import com.atguigu.gmall.common.service.RabbitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class TaskConfig {
    @Autowired
    private RabbitService rabbitService;

    //任务1 将秒杀的商品压入Redis缓存
    //@Scheduled(cron = "0 0 0 * * ? *")//半夜12点
    @Scheduled(cron = "0/5 * * * * ?")//为了测试 每隔5s
    public void task1() {
        System.out.println("定时任务开始执行,时间是:" + new Date());
        //每隔5s产生一个线程 为避免并发 使用MQ
        rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK, MqConst.ROUTING_TASK_1, "");
    }

    //TODO  每天的最后清空当天秒杀的商品
}
